import { AfterViewInit, Component, ElementRef, Input,Output,EventEmitter, OnInit} from '@angular/core';
import { TabComponent } from '../tab/tab.component';

@Component({
  selector: 'nova-tab-group',
  templateUrl: './tab-group.component.html',
  styleUrls: ['./tab-group.component.css']
})
export class TabGroupComponent {
  @Output() indexChange:EventEmitter<number> = new EventEmitter();
  @ContentChildren(TabComponent) tabComps!: QueryList<TabComponent>
  tabOnToggle(label:string){
    console.log(label)
    this.tabComps.forEach((tab)=>{

      if(label != tab.label){
        // 关闭
        tab.close()
      }else{
        tab.open()
      }
    })
  }

  ngAfterViewInit(): void {
    console.log(this.tabComps)
    this.subscribeChildrenEvent()
    
  }
  subscribeChildrenEvent(){
    this.tabComps.forEach((tab)=>{
      tab.onToggle.subscribe(label=>{
        this.tabOnToggle(label)
      })
    })
  }
}

